import http from '@/utils/request'
import { MFunction, EFunctionType } from '../entities'
import store from "@/store"


const getId = () => {
	return new Date().getTime() + Math.round(Math.random() * 100000)
}
const menus: MFunction[] = [
	{
		route: "home",
		sort: 1,
		type: EFunctionType.menu,
		code: 'home' + '-menu',
		component: "/src/views/home.vue",
		icon: "icon-dashboard",
		name: "首页",
		id: getId(),
		parentId: -1,//根路径
	},
	{
		icon: "icon-quanxianguanli",
		name: "权限管理",
		sort: 2,
		type: EFunctionType.menu,
		code: 'permission' + '-menu',
		isCache: true,
		id: getId(),
		parentId: -1,//根路径
		children: [
			{
				route: "permission/role-list",
				component: "/src/modules/permission/views/role-list.vue",
				icon: "icon-jiaoseguanli",
				name: "角色列表",
				isCache: true,
				id: getId(),
				sort: 21,
				type: EFunctionType.menu,
				code: 'permission-role-list' + '-menu',
				parentId: 99999
			},
			{
				route: "permission/role-edit",
				component: "/src/modules/permission/views/role-edit.vue",
				icon: "icon-jiaoseguanli",
				name: "角色详情",
				isCache: true,
				id: getId(),
				sort: 22,
				type: EFunctionType.menu,
				code: 'permission-role-edit' + '-menu',
				parentId: 99999
			},
			{
				route: "permission/function-management",
				component: "/src/modules/permission/views/function-management.vue",
				icon: "icon-gongnengguanli",
				name: "功能管理",
				isCache: true,
				id: getId(),
				sort: 23,
				type: EFunctionType.menu,
				code: 'permission-function-list' + '-menu',
				parentId: 99999
			}
		]
	},
	{
		icon: "icon-account",
		name: "账号管理",
		id: getId(),
		sort: 3,
		type: EFunctionType.menu,
		code: 'account' + '-menu',
		parentId: -1,//根路径
		children: [
			{
				route: "account/user-list",
				component: "/src/modules/account/views/user-list.vue",
				icon: "icon-custom-user",
				name: "用户列表",
				isCache: true,
				id: getId(),
				sort: 33,
				type: EFunctionType.menu,
				code: getId() + '-menu',
				parentId: 99999
			}
		]
	},
	{
		icon: "icon-account",
		name: "设备管理",
		id: getId(),
		sort: 3,
		type: EFunctionType.menu,
		code: 'device' + '-menu',
		parentId: -1,//根路径
		children: [
			{
				route: "device/device-list",
				component: "/src/modules/devices/views/device.list.vue",
				icon: "icon-custom-user",
				name: "设备列表",
				isCache: true,
				id: getId(),
				sort: 33,
				type: EFunctionType.menu,
				code: getId() + '-menu',
				parentId: 99999
			}
		]
	}
];

class MenuServiceTemp {

	//获取权限菜单
	getMenuList(judgePermission: boolean): Promise<MFunction[]> {
		return Promise.resolve(menus);
		// return http.get('/yxd/oa/menu/list').then((menus: any) => {
		// 	menus as MFunction[]
		// 	let userPemission = store.userStore.authorityList as string[]
		// 	let permission = menus.filter((f: MFunction) => userPemission.includes(f.code) && (f.type == EFunctionType.menu || f.type == EFunctionType.page))
		// 	let list = judgePermission ? permission : menus
		// 	list.forEach((item: MFunction) => {
		// 		if (item.parentId != -1) {
		// 			let parent = permission.find((f: MFunction) => f.id == item.parentId)
		// 			if (!parent) return
		// 			if (!parent.children) parent.children = []
		// 			parent.children.push(item)
		// 		}
		// 	})
		// 	return Promise.resolve(list)
		// })
	}
}

const MenuService = new MenuServiceTemp();
export {
	MenuService
}
